<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-cn" xml:lang="zh-cn">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="DC.Type" content="topic">
  <meta name="DC.Title" content="应用一致性备份的生产环境Pod配置（通用）">
  <meta name="product" content="">
  <meta name="DC.Relation" scheme="URI" content="kubernetes_CSI_00062.html">
  <meta name="prodname" content="">
  <meta name="version" content="">
  <meta name="brand" content="30-OceanProtect 备份一体机 1.5.0-1.6.0 帮助中心">
  <meta name="DC.Publisher" content="20240320">
  <meta name="prodname" content="csbs">
  <meta name="documenttype" content="usermanual">
  <meta name="DC.Format" content="XHTML">
  <meta name="DC.Identifier" content="kubernetes_CSI_00066">
  <meta name="DC.Language" content="zh-cn">
  <link rel="stylesheet" type="text/css" href="public_sys-resources/commonltr.css">
  <title>应用一致性备份的生产环境Pod配置（通用）</title>
 </head>
 <body style="clear:both; padding-left:10px; padding-top:5px; padding-right:5px; padding-bottom:5px">
  <a name="kubernetes_CSI_00066"></a><a name="kubernetes_CSI_00066"></a>
  <h1 class="topictitle1">应用一致性备份的生产环境Pod配置（通用）</h1>
  <div>
   <div class="section">
    <h4 class="sectiontitle">操作步骤</h4>
    <ol>
     <li><span>登录Kubernetes集群的任意已配置kubectl工具的节点。</span></li>
     <li><span>对需要进行一致性备份的应用所在Pod添加标签和注解。</span><p></p>
      <ol type="a">
       <li>对Pod添加标签，可通过Pod名或Pod标签指定添加标签的Pod。
        <ul>
         <li>根据Pod名称添加，示例如下。<pre class="screen">kubectl label pod <strong><em>name</em></strong><em> </em>-n <strong><em>namespace</em></strong> hook.dataprotect.backup.io/switch='on'</pre></li>
         <li>根据Pod标签添加，示例如下。<pre class="screen">kubectl label pod -l <strong><em>label</em></strong>=<em><strong>value</strong></em> -n <strong><em>namespace</em></strong> hook.dataprotect.backup.io/switch='on'</pre></li>
        </ul> <p>相关参数如<a href="#kubernetes_CSI_00066__table1343195818318">表1</a>所示。</p></li>
       <li>对Pod添加注解，可通过Pod名或Pod标签指定添加注解的Pod。
        <ul>
         <li>根据Pod名称添加注解，示例如下。<pre class="screen">kubectl annotate pod <strong><em>name </em></strong>-n <strong><em>namespace</em></strong> pre.hook.dataprotect.backup.io/command=<strong><em>cmd_value</em></strong><strong>1</strong>
kubectl annotate pod <strong><em>name</em></strong><em> </em>-n <strong><em>namespace</em></strong> pre.hook.dataprotect.backup.io/container=<em><strong>container_name</strong></em>
kubectl annotate pod <strong><em>name</em></strong><em> </em>-n <strong><em>namespace</em></strong> post.hook.dataprotect.backup.io/command=<strong><em>cmd_value</em></strong><strong>2</strong>
kubectl annotate pod <strong><em>name</em></strong><em> </em>-n <strong><em>namespace</em></strong> post.hook.dataprotect.backup.io/container=<em><strong>container_name</strong></em></pre></li>
         <li>根据Pod标签添加注解，示例如下。<pre class="screen">kubectl annotate pod -l <strong><em>label=value </em></strong>-n <strong><em>namespace</em></strong> pre.hook.dataprotect.backup.io/command=<strong><em>cmd_value1</em></strong>
kubectl annotate pod -l <strong><em>label=value</em></strong><em> </em>-n <strong><em>namespace</em></strong> pre.hook.dataprotect.backup.io/container=<em><strong>container_name</strong></em>
kubectl annotate pod -l <strong><em>label=value</em></strong><em> </em>-n <strong><em>namespace</em></strong> post.hook.dataprotect.backup.io/command=<strong><em>cmd_value2</em></strong>
kubectl annotate pod -l <strong><em>label=value</em></strong><em> </em>-n <strong><em>namespace</em></strong> post.hook.dataprotect.backup.io/container=<em><strong>container_name</strong></em></pre></li>
        </ul> <p>相关参数如<a href="#kubernetes_CSI_00066__table1343195818318">表1</a>所示。</p>
        <div class="tablenoborder">
         <a name="kubernetes_CSI_00066__table1343195818318"></a><a name="table1343195818318"></a>
         <table cellpadding="4" cellspacing="0" summary="" id="kubernetes_CSI_00066__table1343195818318" frame="border" border="1" rules="all">
          <caption>
           <b>表1 </b>命令参数说明
          </caption>
          <colgroup>
           <col style="width:50%">
           <col style="width:50%">
          </colgroup>
          <thead align="left">
           <tr>
            <th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.1.2.2.2.1.2.3.2.3.1.1"><p>参数</p></th>
            <th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.1.2.2.2.1.2.3.2.3.1.2"><p>说明</p></th>
           </tr>
          </thead>
          <tbody>
           <tr>
            <td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.1.2.2.2.1.2.3.2.3.1.1 "><p>name</p></td>
            <td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.1.2.2.2.1.2.3.2.3.1.2 "><p>需要选中的Pod名称。</p></td>
           </tr>
           <tr>
            <td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.1.2.2.2.1.2.3.2.3.1.1 "><p>namespace</p></td>
            <td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.1.2.2.2.1.2.3.2.3.1.2 "><p>需要选中的命名空间名称。</p></td>
           </tr>
           <tr>
            <td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.1.2.2.2.1.2.3.2.3.1.1 "><p>label</p></td>
            <td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.1.2.2.2.1.2.3.2.3.1.2 "><p>需要选中的Pod的标签的key值。</p></td>
           </tr>
           <tr>
            <td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.1.2.2.2.1.2.3.2.3.1.1 "><p>value</p></td>
            <td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.1.2.2.2.1.2.3.2.3.1.2 "><p>需要选中的Pod的标签的value值。</p></td>
           </tr>
           <tr>
            <td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.1.2.2.2.1.2.3.2.3.1.1 "><p>cmd_value1</p></td>
            <td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.1.2.2.2.1.2.3.2.3.1.2 "><p>为PVC创建快照前执行的hook命令。命令参数值示例如下：</p> <pre class="screen">pre.hook.dataprotect.backup.io/command='["/bin/bash", "-c", "mysql -uroot -ppassword -e \"flush tables with read lock\""]'</pre></td>
           </tr>
           <tr>
            <td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.1.2.2.2.1.2.3.2.3.1.1 "><p>cmd_value2</p></td>
            <td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.1.2.2.2.1.2.3.2.3.1.2 "><p>为PVC创建快照后执行的hook命令。命令参数值示例如下：</p> <pre class="screen">post.hook.dataprotect.backup.io/command='["/bin/bash", "-c", "mysql -uroot -ppassword -e \"flush tables with read lock\""]'</pre></td>
           </tr>
           <tr>
            <td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.1.2.2.2.1.2.3.2.3.1.1 "><p>container_name</p></td>
            <td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.1.2.2.2.1.2.3.2.3.1.2 "><p>执行前置/后置命令的容器名称。如果未配置该参数所在行的注解，将默认获取Pod中的第一个容器执行命令。</p></td>
           </tr>
          </tbody>
         </table>
        </div>
        <div class="note">
         <img src="public_sys-resources/note_3.0-zh-cn.png"><span class="notetitle"> </span>
         <div class="notebody">
          <p>当参数cmd_value1或cmd_value2的命令有多条时（如MySQL），可将多条命令批量写入到一个脚本文件中，参数值可输入执行该脚本文件的命令以简化参数值，执行方法示例可参见<a href="kubernetes_CSI_00067.html">应用一致性备份的生产环境Pod配置（容器应用为MySQL）</a>或<a href="kubernetes_CSI_00068.html">应用一致性备份的生产环境Pod配置（容器应用为openGauss）</a>。</p>
         </div>
        </div></li>
      </ol> <p></p></li>
    </ol>
   </div>
   <p></p>
  </div>
  <div>
   <div class="familylinks">
    <div class="parentlink">
     <strong>父主题：</strong> <a href="kubernetes_CSI_00062.html">常见问题</a>
    </div>
   </div>
  </div>
 </body>
</html>